/**
 * @format
 * @Author: TC
 * @Date: 2022-03-04 12:32:52
 * @Last Modified by: TC
 * @Last Modified time: 2025-06-08 12:27:54
 */

/**
 * 个体管理器
 */
export class TickManager {
    private _setObj: Set<any> = null;
    public get mapObj(): Set<any> {
        return this._setObj;
    }

    constructor() {
        this._setObj = new Set();
    }

    /**
     * 添加一个个体
     * @param e
     */
    public add(e: any): void {
        this._setObj.add(e);
    }

    /**
     * 删除一个个体
     */
    public remove(e: any): void {
        if (this._setObj.has(e)) {
            this._setObj.delete(e);
        }
    }

    public tick(dt: number): void {
        this._setObj.forEach((e) => {
            e.tick && e.tick(dt);
        });
    }

    /**
     * 释放
     */
    public release(): void {
        this._setObj.forEach((e) => {
            e.release && e.release();
        });
        this._setObj.clear();
        this._setObj = null;
    }
}
